<?php
namespace app\atxunda\model;
use think\Model;
use think\Input;
use think\Cookie;

class Admin extends Model
{
    public static function login($name, $password)
    {

        $where['admin_name'] = $name;
        $where['admin_password'] = md5(trim($password));

        $user = self::getDetail($where);
        if ($user) {
            unset($user["admin_password"]);
            Cookie::set('admin',serialize($user),3600*24);
            session("admin", $user);
            return true;
        }else{
            return false;
        }
    }


    // 查询一条数据
    public static function search($name){
        $user = self::getDetail(['admin_name'=>$name]);
        return $user;
        // dump($user['admin_password']);
    }

    //更改用户密码

    public static function updatepassword($name,$newpassword){
        $where['admin_name'] = $name;
        $user = self::where($where)->update(['admin_password' => md5($newpassword)]);
        if ($user) {
            return true;
        }else{
            return false;
        }
    }

    
    public function getAdminName($id){
        return self::where('admin_id',$id)->value('admin_name');
    }


    public function getDetail($where){
        return self::where($where)->find();
    }
} 
 